// JavaScript Document
define(function (require, exports, module) {
	var Masker=require("Masker");
	
	var Loading=function(){
	}
	Loading.prototype.masker=null;
	Loading.prototype.element=null;
	Loading.prototype.tips=null;
	Loading.prototype.wrapper=null;
	Loading.prototype.opened=false;
	
	Loading.prototype.create=function(){
		var self=this;
		this.element=document.createElement("div");
		this.element.className="ht_loading close";
		
		this.tips=document.createElement("p");
		this.tips.innerHTML="请稍候";
		
		this.wrapper=document.createElement("div");
		this.wrapper.className="wrapper";
		this.wrapper.appendChild(this.tips);
		
		
		
		
		this.element.appendChild(this.wrapper);
		document.body.appendChild(this.element)
	}
	Loading.prototype.setElement=function(element){
		this.element=element;
		this.opened=true;
	}
	Loading.prototype.setMasker=function(masker){
		this.masker=masker;
	}
	Loading.prototype.open=function(){
		if(this.opened){
			return false;
		}
		var self=this;
		if(this.masker==null){
			this.masker=new Masker();
		}else{
			//console.log("masker have");
		}
		this.masker.open()
		if(this.element==null){
			this.create();
		}else{
			//console.log("loading have");
		}
		var self=this;
		setTimeout(function(){
			self.element.className="ht_loading open"
		},0)
		this.opened=true;
		return this;
	}
	Loading.prototype.close=function(){
		if(!this.opened){
			return false;
		}
		if(this.masker!=null){
			this.masker.close()
		}
		var self=this;
		if(this.element!=null){
			this.element.className="ht_loading close"
			var timer=setTimeout(function(){self.remove();self.opened=false;},500);
		}
	}
	Loading.prototype.hide=function(){
		$(this.element).hide();
		this.masker.hide()
	}
	Loading.prototype.remove=function(){
		$(this.element).remove();
		
		//this.element.parentNode.removeChild(this.element)
		this.element=null;
		this.masker=null;
		//document.body.removeChild(this.element)
	}
	module.exports = Loading;
});